home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr11 / pdox693.zip / TI154.ASC < prev    next >
Text File  |  1992-08-12  |  9KB  |  331 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Paradox                                NUMBER  :  154
  9.   VERSION  :  2.0 & up
  10.        OS  :  DOS
  11.      DATE  :  August 12, 1992                          PAGE  :  1/5
  12.  
  13.     TITLE  :   Variables and Wildcards in PAL Queries
  14.  
  15.  
  16.  
  17.  
  18.   There are two ways of performing queries in a PAL application.
  19.   The first way is through a script that uses commands that follow
  20.   the interactive Paradox menu.  The other way is through a script
  21.   using the PAL QUERY/ENDQUERY command.  Each method has its
  22.   comparative advantages and disadvantages.  In this document, we
  23.   will call the first method a Menu Equivalent Query and the
  24.   second, a Saved Query Image.
  25.  
  26.   Menu Equivalent Queries can be saved by selecting {Scripts}
  27.   {BeginRecord} then choosing the keystrokes for filling out a
  28.   query.  This is a typical Menu Equivalent Query on a table called
  29.   SAMPLE:
  30.  
  31.   {Ask} {Sample} Right Check "John Doe" Enter Check "123 Anystreet"
  32.   DO_IT!
  33.  
  34.   Saved Query Images are created by filling out a query form
  35.   interactively then selecting {Scripts} {Querysave}.  This is a
  36.   typical example as it appears in the script.
  37.  
  38.   Query
  39.  
  40.    Sample |      Name      |      Address        |
  41.           | Check John Doe | Check 123 Anystreet |
  42.           |                |                     |
  43.           |                |                     |
  44.  
  45.   Endquery
  46.  
  47.   These two methods are useful for saving time when performing the
  48.   same query repeatedly, but some modifications must be made to use
  49.   variables and wildcard operators in a query.
  50.  
  51.   First, for Saved Query Images you can use variables by preceding
  52.   them with a tilde (~).  In the example above, if you wanted a
  53.   variable name and address you would change it to the following:
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Paradox                                NUMBER  :  154
  75.   VERSION  :  2.0 & up
  76.        OS  :  DOS
  77.      DATE  :  August 12, 1992                          PAGE  :  2/5
  78.  
  79.     TITLE  :   Variables and Wildcards in PAL Queries
  80.  
  81.  
  82.  
  83.  
  84.   NAME="John Doe"                      ; Assign values to the
  85.   ADDRESS="123 Anystreet"              ; NAME and ADDRESS variables
  86.   Query
  87.  
  88.    Sample |      Name      |      Address       |
  89.           | Check ~NAME    | Check ~ADDRESS     |
  90.           |                |                    |
  91.           |                |                    |
  92.  
  93.   Endquery
  94.   DO_IT!
  95.  
  96.   For this query to work properly, the variables NAME and ADDRESS
  97.   must be assigned values (e.g. "John Doe" and "AnyStreet").  This
  98.   query searches for an exact match based on the values of NAME and
  99.   ADDRESS at the time of the query.  To use wildcard operators, you
  100.   must make the wildcard operator part of the query statement, not
  101.   part of the variable assignment.  For instance, to find all
  102.   addresses on Anystreet, assign, "Anystreet" to the ADDRESS
  103.   variable.  Then type ..~ADDRESS in the Address field of the query
  104.   statement.  For example,
  105.  
  106.   NAME="John Doe"                      ; Assign values to the
  107.   ADDRESS="123 Anystreet"              ; NAME and ADDRESS variables
  108.   Query
  109.  
  110.    Sample |      Name      |      Address       |
  111.           | Check ~NAME    | Check ..~ADDRESS   |
  112.           |                |                    |
  113.           |                |                    |
  114.  
  115.   Endquery
  116.   DO_IT!
  117.  
  118.   To use variables and wildcard operators in a Menu Equivalent
  119.   Query, there are two methods, the TYPEIN command and a Field
  120.   Assignment statement (e.g. [Name] = NAME).  The TYPEIN command
  121.   simulates typing characters into Paradox from the keyboard.  Its
  122.   effect is similar to a quoted string (e.g. "John Doe"), but it
  123.   allows the characters to be stored in a variable.  For example:
  124.  
  125.   TBL="sample"                         ; Assign the TBL, NAME
  126.   NAME="john.."                        ;   and ADDRESS variables
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Paradox                                NUMBER  :  154
  141.   VERSION  :  2.0 & up
  142.        OS  :  DOS
  143.      DATE  :  August 12, 1992                          PAGE  :  3/5
  144.  
  145.     TITLE  :   Variables and Wildcards in PAL Queries
  146.  
  147.  
  148.  
  149.  
  150.   ADDRESS="123 Anystreet"
  151.  
  152.   These tools in combination with other PAL commands can create
  153.   very flexible queries.  For example:
  154.  
  155.   {Ask} SELECT TBL Right Check TYPEIN NAME Enter Check TYPEIN
  156.   ADDRESS DO_IT!
  157.  
  158.   Note: we used the "Right" command to move to the Name field
  159.   before using the TYPEIN command.
  160.  
  161.   Like the TYPEIN command, a Field Assignment statement (=) also
  162.   simulates typing the value from the keyboard.  Unlike the TYPEIN
  163.   command, it is not necessary to move to the field before
  164.   performing a Field Assignment statement.  The following is an
  165.   example of how to use a Field assignment statement.  For better
  166.   readability, the commands are placed on different lines and each
  167.   line is commented.
  168.  
  169.           {Ask} SELECT TBL       ; Select table to query
  170.           Right Check            ; Move right and check Name field
  171.           [Name]=NAME            ; Assign NAME variable to Name
  172.                                  ; field
  173.           Enter                  ; Enter moves cursor to the right
  174.           Check                  ; Check Address field
  175.           [Address]=ADDRESS      ; Assign Address variable to
  176.                                  ; Address
  177.           DO_IT!                 ; Press [F2] to process query
  178.  
  179.   We also have the flexibility to make the Menu Equivalent query
  180.   perform wildcard searches.  By setting the NAME variable, equal
  181.   to "john.." the query will be a wildcard search in the NAME
  182.   field.  The query still searches for an exact match in the
  183.   Address field.  In contrast to a Saved Query Image, wildcard
  184.   operators can be included as part of the variable assignment.
  185.  
  186.   To perform this query on a variable table, a tilde variable can
  187.   not be substituted for the table name "Sample."
  188.  
  189.   To perform the same query on variable tables you need to use a
  190.   Menu Equivalent Query along with the SELECT command.  If you
  191.   wanted the first example to be performed on several tables
  192.   instead of just SAMPLE you would change it to the following:
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Paradox                                NUMBER  :  154
  207.   VERSION  :  2.0 & up
  208.        OS  :  DOS
  209.      DATE  :  August 12, 1992                          PAGE  :  4/5
  210.  
  211.     TITLE  :   Variables and Wildcards in PAL Queries
  212.  
  213.  
  214.  
  215.  
  216.   TBL="sample"            ; Assign value to TBL variable
  217.  
  218.   {Ask} SELECT TBL Right Check "John Doe" Enter Check
  219.   "123 Anystreet" DO_IT!
  220.  
  221.   Note: Where the first example had the actual table name in curly
  222.   braces "{Sample}", we have placed the SELECT command and the
  223.   variable TBL which is equal to a table name.  Changing the value
  224.   of the TBL variable changes the table that is queried.
  225.  
  226.   An important issue exists when using Menu Equivalent queries and
  227.   Query Saved images. In your application, you may not want a query
  228.   to be performed using every variable.  For example, you may want
  229.   to search for "John Doe" regardless of what the address is.  To
  230.   do so, you might think that not assigning a value to the ADDRESS
  231.   variable is sufficient.  However, it is not!  When a variable is
  232.   not assigned a value, the variable by default equals null.  Thus,
  233.   the query would search for "John Doe" in the name field AND the
  234.   null value "" in the Address field.
  235.  
  236.   To perform this query correctly, you must use the ISASSIGNED
  237.   function to determine if the variable has been assigned a value.
  238.   When the variable has been assigned value, the value in the
  239.   variable is placed into the query.  For example,
  240.  
  241.   TBL="sample"                         ; Assign the TBL variable
  242.  
  243.   @ 5,5
  244.   ?? "What name would you like to search for? "
  245.   ACCEPT "A20" to NAME                 ; Get NAME from user
  246.   @ 10,5
  247.   ?? "What address would you like to search for? "
  248.   ACCEPT "A35" to ADDRESS              ; Get ADDRESS from user
  249.  
  250.           {Ask} SELECT TBL
  251.           Right Check
  252.           [Name] = NAME                    ; Assign Name field
  253.           Enter Check
  254.           IF NOT ISASSIGNED(ADDRESS) THEN  ; If Address is assigned
  255.             [Address] = ADDRESS            ;  place into the field
  256.           ENDIF
  257.           DO_IT!                           ; Process query
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Paradox                                NUMBER  :  154
  273.   VERSION  :  2.0 & up
  274.        OS  :  DOS
  275.      DATE  :  August 12, 1992                          PAGE  :  5/5
  276.  
  277.     TITLE  :   Variables and Wildcards in PAL Queries
  278.  
  279.  
  280.  
  281.  
  282.   As you can see, we use the ACCEPT command to get values from the
  283.   user, and we have the option of leaving the ADDRESS variable
  284.   empty by using an IF statement and the ISASSIGNED function to
  285.   test for ADDRESS being assigned a value.  If ADDRESS is assigned
  286.   a value then it is assigned to the field.
  287.  
  288.   For additional commands that can be used in conjunction with
  289.   queries see the PAL User's Guide.
  290.  
  291.   DISCLAIMER: You have the right to use this technical information
  292.   subject to the terms of the No-Nonsense License Statement that
  293.   you received with the Borland product to which this information
  294.   pertains.
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.